package com.taotao.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.common.EasyUIResult;
import com.taotao.common.TaotaoConstant;
import com.taotao.dao.UserInfoDao;
import com.taotao.pojo.UserInfo;
import com.taotao.service.UserInfoService;

@Service
public class UserInfoServiceImpl implements UserInfoService {
	
	@Resource(name="userInfoDao")
	private UserInfoDao userInfoDao;

	@Override
	public EasyUIResult<UserInfo> selectList(Integer pageNum,Integer pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<UserInfo> userList = userInfoDao.selectList();
		PageInfo<UserInfo> pageInfo = new PageInfo<>(userList);
		return new EasyUIResult<UserInfo>(pageInfo.getTotal(),pageInfo.getList());
	}

	@Override
	public Integer add(UserInfo userInfo) {
		userInfo.setCreateDateTime(new Date());
		userInfo.setDeleteFlag(TaotaoConstant.DELETE_FLAG.yes_flag);
		return userInfoDao.add(userInfo);
	}

	@Override
	public Integer delete(String ids) {
		String idArray[] = ids.split(",");
		List<Integer> idList = new ArrayList<Integer>();
		for(String id :idArray){
			idList.add(Integer.parseInt(id));
		}
		return userInfoDao.delete(idList);
	}

	@Override
	public void update(UserInfo userInfo) {
		userInfo.setModifyDateTime(new Date());
		userInfoDao.update(userInfo);
	}

	@Override
	public UserInfo selectUserInfoById(String id) {
		return userInfoDao.selectUserInfoById(id);
	}

	

}
